<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>选择地址</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no,email=no,address=no" />
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <link rel="stylesheet" href="../css/common.css" />
    <link rel="stylesheet" href="../css/y_index.css" />
    <link rel="stylesheet" href="../js/drop/dropload.css" />
</head>

<body>
    <div class="addressBox" style="padding-bottom: 1.4rem;">
        <ul>
            <li class="bw mb20">
                <div class="plr24 ptb30 bdb font15 col3">
                    <p class="flex_sb mb20"><span>勇仔</span><span>15812874182</span></p>
                    <p>广东省东莞市南城区宏图路</p>
                </div>
                <div class="plr24 flex_sb">
                    <label class="h100 flex_a col3">
                        <input type="radio" name="radio" hidden class="chose_addr" value="1" checked>
                        <span class="roudBox border"></span>
                        <i class="font15 ml20 color2">默认地址</i>
                    </label>
                    <div class="flex jce">
                        <em class="editBox h100 flex_a"><span class="mr20 col9 font14">编辑</span><img src="../img/edit.png" alt=""></em>
                        <em class="delBox h100 flex_a ml40"><span class="mr20 col9 font14">删除</span><img src="../img/del.png" alt=""></em>
                    </div>
                </div>
            </li>
            <li class="bw mb20">
                <div class="plr24 ptb30 bdb font15 col3">
                    <p class="flex_sb mb20"><span>勇仔</span><span>15812874182</span></p>
                    <p>广东省东莞市南城区宏图路</p>
                </div>
                <div class="plr24 flex_sb">
                    <label class="h100 flex_a col3">
                        <input type="radio" name="radio" hidden class="chose_addr" value="2">
                        <span class="roudBox border"></span>
                        <i class="font15 ml20">默认地址</i>
                    </label>
                    <div class="flex jce">
                        <em class="editBox h100 flex_a"><span class="mr20 col9 font14">编辑</span><img src="../img/edit.png" alt=""></em>
                        <em class="delBox h100 flex_a ml40"><span class="mr20 col9 font14">删除</span><img src="../img/del.png" alt=""></em>
                    </div>
                </div>
            </li>
        </ul>
    </div>
    <div class="pos_f_b ptb30 bgf5">
        <a href="./ser_add.html" class="main_btn">新增地址</a>
    </div>
</body>

</html>
<script type="text/javascript" src="../js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="../js/dlc.js"></script>
<script type="text/javascript" src="../js/drop/dropload.min.js"></script>
<script>
var page = 0;
// 每页展示10个
var size = 10;
var tower, yong;
$(function() {
    //设备默认地址
    $('.addressBox').on('click', '.chose_addr', function() {
        console.log($(this).is(':checked'));
        if ($(this).is(':checked')) {
            $(this).parent('label').find('i').text('默认地址').addClass('color2').end().parents('li').siblings().find('i').text('设为默认').removeClass('color2');
        }
    });

    //编辑
    $('.editBox').click(function() {
        location.href = './ser_add.html';
    });
    //删除
    $('.delBox').click(function() {
        dlctipbox.confirm('确认要删除吗？', function() {
            dlctipbox.show('正在删除中')
        })
    });

    $('.addressBox').dropload({
        scrollArea: window,
        domUp: {
            domClass: 'dropload-up',
            domRefresh: '<div class="dropload-refresh">↓下拉刷新</div>',
            domUpdate: '<div class="dropload-update">↑释放更新</div>',
            domLoad: '<div class="dropload-load"><span class="loadings"></span>加载中...</div>'
        },
        domDown: {
            domClass: 'dropload-down',
            domRefresh: '<div class="dropload-refresh">↑上拉加载更多</div>',
            domLoad: '<div class="dropload-load"><span class="loadings"></span>加载中...</div>',
            domNoData: '<div class="dropload-noData">暂无更多数据</div>'
        },
        loadUpFn: function(me) {
            var str = '';
            dlc_request('/dcmj-api/api/findOpenIdDevice', { page: 1, pageSize: size, openId: getUrlParam('openId'), tower: tower }, function(res) {
                console.log(res);
                if (res.code == 1) {
                    res.data.forEach(function(item, index) {
                        str += '<li class="bw mt20 mlr30 border-r1 plr24">' +
                            '<div class="flex_sb bdb h150">' +
                            '<span class="font18 col3">' + item.storeyName + item.storey + item.deviceNum + '</span>' +
                            '<em class="flex_a">' +
                            '<span class="homeBtn flex_aj  ' + (item.taskStatus == 1 ? 'col9' : 'color1') + '  mr10 openBtn" ' + (item.taskStatus == 1 ? 'style="border-color:#999"' : '') + '  data-opentime="' + item.openTime + '" data-closetime="' + item.closeTime + '"  data-status="' + item.taskStatus + '">' + (item.taskStatus == 1 ? '定时关' : '定时开') + '</span><span  class="homeBtn flex_aj bgc1 colw openDoor" data-buttonid="' + item.buttonId + '">开门</span>' +
                            '</em>' +
                            '</div>' +
                            '<div class="flex_a h110 details ' + (item.taskStatus == 2 ? 'col3' : 'col9') + '" data-id="' + item.id + '" data-deviceid="' + item.deviceId + '" data-name="' + (item.storeyName + item.storey + item.deviceNum) + '">' +
                            '<span>' + item.openTime.split(" ")[0] + '</span>' +
                            '<div class="flex_aj flex1">' +
                            '<span class="font16 mr20">' + item.openTime.split(" ")[1].split(':')[0] + ':' + item.openTime.split(" ")[1].split(':')[1] + '</span><span class="col9 font14">开门</span>' +
                            '<em class="flex_a mlr24"><span class="roundBox bgc1"></span><span class="h_line mlr10"></span><span class="roundBox bgc1"></span></em>' +
                            '<span class="font16 mr20">' + item.closeTime.split(" ")[1].split(':')[0] + ':' + item.closeTime.split(" ")[1].split(':')[1] + '</span><span class="col9 font14">关门</span>' +
                            '</div>' +
                            '<img src="../img/ic_arrow.png" class="arrow_r" alt="">' +
                            '</div>' +
                            '</li>';
                    });
                    $('.addressBox ul').html(str);
                    // 每次数据加载完，必须重置
                    me.resetload();
                    // 重置页数，重新获取loadDownFn的数据
                    page = 1;
                    // 解锁loadDownFn里锁定的情况
                    me.unlock();
                    me.noData(false);
                }
            });
        },
        loadDownFn: function(me) {
            //获取分类
            if (page == 0) {
                dlc_request('/dcmj-api/api/allTower', { 'openId': getUrlParam('openId') }, function(res) {
                    console.log(res);
                    var str = '';
                    if (res.code === 1) {
                        try {
                            tower = res.data[0];
                        } catch (e) {}
                        res.data.forEach(function(item, index) {
                            str += '<div class="' + (index == 0 ? 'active' : '') + '">' + item + '<span class="' + (index == 0 ? 'b_line' : '') + '"></span></div>';
                        });
                        $('.tabBox').html(str);
                        console.log(tower);
                        yong = me;
                        getData(yong);
                    }
                });
            } else {
                yong = me;
                getData(yong);
            }

        },
        threshold: 50
    });
})

function getData(me) {
    page++;
    if (page == 1) {
        dlctipbox.loading('载入中');
    }
    // 拼接HTML
    var str = '';
    var data = { page: page, pageSize: size, openId: getUrlParam('openId'), tower: tower };
    dlc_request('/dcmj-api/api/findOpenIdDevice', data, function(res) {
        dlctipbox.clear();
        if (res.code == 1) {
            var arrLen = res.data.length;
            if (arrLen > 0) {
                res.data.forEach(function(item, index) {
                    str += '<li class="bw mt20 mlr30 border-r1 plr24">' +
                        '<div class="flex_sb bdb h150">' +
                        '<span class="font18 col3">' + item.storeyName + item.storey + item.deviceNum + '</span>' +
                        '<em class="flex_a">' +
                        '<span class="homeBtn flex_aj ' + (item.taskStatus == 1 ? 'col9' : 'color1') + ' mr10 openBtn" ' + (item.taskStatus == 1 ? 'style="border-color:#999"' : ' ') + '   data-opentime="' + item.openTime + '" data-closetime="' + item.closeTime + '" data-status="' + item.taskStatus + '">' + (item.taskStatus == 1 ? '定时关' : '定时开') + '</span><span  class="homeBtn flex_aj bgc1 colw openDoor"  data-buttonid="' + item.buttonId + '">开门</span>' +
                        '</em>' +
                        '</div>' +
                        '<div class="flex_a h110 details ' + (item.taskStatus == 2 ? 'col3' : 'col9') + '"   data-id="' + item.id + '" data-deviceid="' + item.deviceId + '" data-name="' + (item.storeyName + item.storey + item.deviceNum) + '">' +
                        ' <span>' + item.openTime.split(" ")[0] + '</span>' +
                        '<div class="flex_aj flex1">' +
                        '<span class="font16 mr20">' + item.openTime.split(" ")[1].split(':')[0] + ':' + item.openTime.split(" ")[1].split(':')[1] + '</span><span class="col9 font14">开门</span>' +
                        '<em class="flex_a mlr24"><span class="roundBox bgc1"></span><span class="h_line mlr10"></span><span class="roundBox bgc1"></span></em>' +
                        '<span class="font16 mr20">' + item.closeTime.split(" ")[1].split(':')[0] + ':' + item.closeTime.split(" ")[1].split(':')[1] + '</span><span class="col9 font14">关门</span>' +
                        '</div>' +
                        '<img src="../img/ic_arrow.png" class="arrow_r" alt="">' +
                        '</div>' +
                        '</li>';
                });
                // 如果没有数据
            } else {
                // 锁定
                me.lock();
                // 无数据
                me.noData();
            }
            // 插入数据到页面，放到最后面
            if (page == 1) {
                $('.addressBox ul').html(str);
            } else {
                $('.addressBox ul').append(str);
            }
            // 每次数据插入，必须重置
            me.resetload();
        }
    });
}
</script>